<%-- 
    Document   : paginaSessao
    Created on : 08/03/2014, 18:19:45
    Author     : jordan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Pagina Sessao</title>
    </head>
    <body>
        <jsp:useBean id="usuario" class="beans.Usuario" scope="session"/>
        <jsp:setProperty name="usuario" property="senhaConfirma" param="senha"/>
        <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost/coleta_seletiva"
            user="root" password=""/>
        <sql:query dataSource="${snapshot}" var="result">
            SELECT *, cast(id_tipo_usuario as char) as tipo FROM usuario WHERE login=?
            <sql:param value="${param.login}"/>
        </sql:query>
        <c:if test="${result.rowCount>0}">
            ID: <c:out value="${result.rows[0].id}"/><br/>
            Login: <c:out value="${result.rows[0].login}"/><br/>
            Senha: <c:out value="${result.rows[0].senha}"/><br/>
            <c:if test="${usuario.senhaConfirma==result.rows[0].senha}">
                Bem-vindo!
                <c:set var="id" value="${result.rows[0].id}" scope="session"/>
                <c:set var="login" value="${result.rows[0].nome}" scope="session"/>
                <c:set var="tipoUsuario" value="${result.rows[0].tipo}" scope="session"/>
                <c:redirect url="index.jsp"/>
            </c:if>
            <c:if test="${usuario.senhaConfirma!=result.rows[0].senha}">
                <c:set var="login" value="${result.rows[0].nome}" scope="page"/>
                <c:redirect url="login.jsp?error=13,W;"/>
            </c:if>
        </c:if>
        <c:if test="${result.rowCount<=0}">
            <c:redirect url="login.jsp?error=13,W;"/>
        </c:if>
    </body>
</html>
